<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head th:include="include::head"></head>
<body class="gray-bg">
<div class="layui-anim layui-anim-upbit layui-fluid">
    <div class="layui-row layui-col-space15 table-search">
        <div class="layui-col-md12">
            <div class="layui-btn-group" lay-filter="button-demo">
                <th:block th:each="button : ${button}" th:if="${button.type == 'tool_button'}">
                    <th:block th:if="${button.eventType == 'event_export'}">
                        <a th:class="${button.perClass +' '+ button.eventType}" th:href="${button.perHref}" th:utext="${button.perName}"></a>
                    </th:block>
                    <th:block th:if="${button.eventType != 'event_export'}">
                        <button th:class="${button.perClass +' '+ button.eventType}" th:href="${button.perHref}" th:value="${button.perName}" th:utext="${button.perName}"></button>
                    </th:block>
                </th:block>
            </div>
            <table class="layui-hide" id="table" lay-filter="demo"></table>
            <table class="layui-hide" id="tables" lay-filter="demos"></table>
        </div>
    </div>
</div>
<div th:include="include::onload"></div>
<script type="text/html" id="barDemo">
    <button th:each="button : ${button}" th:if="${button.type == 'menu_button'}" th:class="${button.perClass}" th:href="${button.perHref}" th:lay-event="${button.eventType}" th:value="${button.perName}" th:utext="${button.perName}"><i th:class="${button.perIcon}"></i></button>
</script>
<script  th:inline="javascript">
    layui.config({
        base: '/js/layer/module/'//模块存放的目录
    }).use(['tabular','table'], function(){
        var tabular = layui.tabular,
            table = layui.table,
            statetype = [[${diy['state_type']}]],
            url = "/admin/basics/dictionaries";
            options = {
            elem: '#table',
            url:url,
            onlyId:"diyTypeId",
            method:'post',
            id:'diyType-table',
            height: '370',
            cellMinWidth: 150,
            cols:[
                [
                    {type:'numbers',title: '序号', fixed: 'left'}
                    ,{field:'diyTypeName',event:'dictionaries',title: '名称', sort: true}
                    ,{field:'diyTypeRoute',title: '标识',event:'dictionaries',sort: true}
                    ,{field:'isState',align:'center', title: '状态',sort: true,templet: function (option) {
                        return $.common.initDity(statetype,option.isState);
                    }}
                    ,{field:'remarks', title: '备注',sort: true}
                    ,{field:'addDate', title: '创建时间',fixed: 'right', sort: true,templet: function (option) {
                        return $.date.stringDate(option.addDate);
                    }}
                    ,{width:'10%', align:'center',fixed: 'right', toolbar: '#barDemo'}
                ]
            ],
            ispage:false
            },optionss = {
            elem: '#tables',
            onlyId:"dictionaryId",
            id:'dictionaries-table',
            height: '320',
            cellMinWidth: 220,
            data:[],
            cols:[
                [
                    {type:'numbers',title: '序号', fixed: 'left'}
                    ,{field:'dictionaryName',fixed: 'left',title: '字典名称', sort: true,templet: function (option) {
                        return "<span class='" + option.dictionaryClass + "'>"+option.dictionaryName+"</span>";
                    }}
                    ,{field:'dictionaryRoute',title: '字典标识',sort: true}
                    ,{field:'isState',align:'center', title: '状态',sort: true,templet: function (option) {
                        return $.common.initDity(statetype,option.isState);
                    }}
                    ,{field:'remarks', title: '备注',sort: true}
                    ,{field:'addDate', title: '创建时间',fixed: 'right', sort: true,templet: function (option) {
                        return $.date.stringDate(option.addDate);
                    }}
                    ,{width:'10%', align:'center',fixed: 'right', toolbar: '#barDemo'}
                ]
            ],
            ispage:false
        };
        //监听搜索
        tabular.search();
        //初始化表格
        tabular.init(options);
        tabular.init(optionss);
        table.on('tool(demo)', function(obj){
            var data = obj.data, //获得当前行数据
                layEvent = obj.event, //获得 lay-event 对应的值
                url = $(this).attr('href');
            if(layEvent == 'dictionaries'){
                optionss.data = data.dictionaryList;
                tabular.init(optionss);
            }else if(layEvent == 'event_delect'){
                //询问框
                Layer.showConfirm("<p style='color: red'>确认删除吗？删除后不可恢复!</p>",function(){
                    post(url,{"baseId":data.diyTypeId});
                });
            }else{
                Layer.openDialog($(this).val(),url+"?baseId="+data.diyTypeId);
            }
        });

        table.on('tool(demos)', function(obj){
            var data = obj.data, //获得当前行数据
                layEvent = obj.event, //获得 lay-event 对应的值
                url = $(this).attr('href');
            if(layEvent == 'event_delect'){
                //询问框
                Layer.showConfirm("<p style='color: red'>确认删除吗？删除后不可恢复!</p>",function(){
                    post(url,{"baseId":data.dictionaryId,"showType":"dictionaries"});
                });
            }else{
                Layer.openDialog($(this).val(),url+"?baseId="+data.dictionaryId+"&showType=dictionaries");
            }
        });
        $("body").on("click",".event_add",function () {
            Layer.openDialog($(this).val(),$(this).attr('href'));
        });
    });

function post(url,date) {
    $.achieve.post(url,date,function (result) {
        if(result.status == "success"){
            Layer.showSucMsg(result.result);
            setTimeout("location.reload()",1000);
        }else{
            Layer.showFailMsg(result.errorMsg);
        }
    });
}
</script>
</body>
</html>